import Vue from 'vue'
import Router from 'vue-router'
import Routes from '@/routes'
import global_info from'~/data.json'
import Utils from '~/js/Utils'
import myaxios from '~/js/myaxios'
import alert from '@/components/Alert/Alertjs'
import { mapGetters,mapMutations,mapActions,mapState} from 'vuex'

Vue.use(Router);
const router = new Router({
  mode:'history',
  routes:Routes.routes,
  scrollBehavior(to,from,savedPosition){
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
});
//自定义指令 v-focus 元素获得焦点
// Vue.directive('focus',{
//   //当绑定元素插入到 DOM 中
//   bind:function(el,binding,vnode){
//     //绑定时调用 可以初始化数据
//     console.log('bind',el)
//   },
//   inserted:function (el,binding,vnode) {
//     // 被绑定元素插入父节点时调用
//     el.focus()
//     console.log('inserted',el)
//   },
//   update:function (el,binding,vnode,oldVnode) {
//     //被绑定元素所在的模板更新时调用，而不论绑定值是否变化
//     console.log('update',el)
//   },
//   componentUpdated:function (el,binding,vnode,oldVnode) {
//     //被绑定元素所在模板完成一次更新周期时调用
//     console.log('componentUpdated',el)
//   },
//   unbind:function (el,binding,vnode) {
//     //指令与元素解绑时调用
//     console.log('unbind',el)
//   }
// })
window.Tools={
  Router:router,
  Routes:Routes,
  global_info:global_info,
  Utils:Utils,
  myaxios:myaxios,
  alert:alert,
  mapGetters:mapGetters,
  mapActions:mapActions,
  mapMutations:mapMutations,
  mapState:mapState
};
export default router
